<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb class="navigation">
      <el-breadcrumb-item :to="{ path: '/mapm' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>审核管理</el-breadcrumb-item>
      <el-breadcrumb-item>补发审核</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 主体区域 -->
    <el-card class="notice">
      <h4>&nbsp;&nbsp;补发审核</h4>
      <!-- 搜索区 -->
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrderList">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!--用户列表区-->
      <el-table :data="orderlist" border stripe>
        <el-table-column label="#" type="index"> </el-table-column>
        <el-table-column label="订单编号" prop="applyId"> </el-table-column>
        <el-table-column label="身份证号" prop="applyIdnum"> </el-table-column>
        <el-table-column label="申请人姓名" prop="applyName"> </el-table-column>
        <el-table-column label="联系电话" prop="applyTele"> </el-table-column>
        <el-table-column label="需要补发的门牌号" prop="oldHouse" width="150px"></el-table-column>
        <el-table-column label="具体地址" prop="adressString"> </el-table-column>
        <el-table-column label="操作" width="220px">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="通过" placement="top" :enterable="false">
              <el-button type="primary" icon="el-icon-success" size="mini" @click="passOrder(scope.row)">
              </el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="拒绝" placement="top" :enterable="false">
              <el-button type="danger" icon="el-icon-error" size="mini" @click="rejectOrder(scope.row)">
              </el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="查看理由" placement="top" :enterable="false">
              <el-button type="info" icon="el-icon-circle-plus-outline" size="mini"
                @click="showDetailedInformation(scope.row)">
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.pageNum" :page-sizes="[1, 2, 5, 10]" :page-size="queryInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
      <!-- 查看理由弹出框 -->
      <el-dialog :visible.sync="setInformationDialogVisible" width="30%">
        <el-descriptions title="申请理由" direction="vertical" border>
          <el-descriptions-item>{{ applyReason }}</el-descriptions-item>
        </el-descriptions>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="setInformationDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 填写拒绝理由 -->
      <el-dialog title="拒绝理由" :visible.sync="DialogVisible" width="30%">
        <el-form :model="reject" ref="rejectForm" :rules="rejectForm">
          <el-form-item>
            <el-input v-model="reject.applyId" disabled></el-input>
          </el-form-item>
          <el-form-item prop="reason">
            <el-input type="textarea" v-model="reject.reason"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="rejects('rejectForm')">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'HouseAudit',
  data () {
    return {
      // 获取用户列表的参数
      queryInfo: {
        query: '',
        // 当前页码
        pageNum: 1,
        // 当前每页显示多少条数据
        pageSize: 5
      },
      orderlist: [],
      total: 0,
      setInformationDialogVisible: false,
      DialogVisible: false,
      applyReason: '',
      reject: {
        reason: '',
        applyId: ''
      },
      // 拒绝规则
      rejectForm: {
        reason: [
          { required: true, message: '请填写拒绝理由', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表
    async getOrderList () {
      const { data: res } = await this.$axios.get('pogapply-record/getreissuelist', {
        params: this.queryInfo
      })
      if (res.code !== 200) {
        return this.$message.error(res.message)
      }
      this.orderlist = res.data.list
      this.total = res.data.total
    },
    // 监听pagesize改变的事件
    handleSizeChange (newSize) {
      this.queryInfo.pageSize = newSize
      this.getOrderList()
    },
    // 监听页码值改变的事件
    handleCurrentChange (newPage) {
      this.queryInfo.pageNum = newPage
      this.getOrderList()
    },
    // 通过订单
    async passOrder (row) {
      const { data: res } = await this.$axios.post(
        'pogexamrecord/reissuerecord/accept',
        {
          examAns: 2,
          applyIdString: row.applyId
        }
      )
      if (res.code === 200) {
        this.$message.success('已通过该补发申请')
      } else {
        this.$message.error(res.message)
      }
      this.getOrderList()
    },
    // 拒绝订单
    async rejects (rejectForm) {
      const { data: res } = await this.$axios.post(
        'pogexamrecord/reissuerecord/refuse', {
          examReason: this.reject.reason,
          examAns: 1,
          applyIdString: this.reject.applyId
        }
      )
      if (res.code !== 200) {
        this.$message.error(res.message)
      }
      this.$message.success(res.message)
      this.getOrderList()
      this.DialogVisible = false
      this.$refs[rejectForm].resetFields()
    },
    async rejectOrder (row) {
      this.DialogVisible = true
      this.reject = row
    },
    // 展示订单详细信息的对话框
    async showDetailedInformation (row) {
      const reason = row.applyReason.replace(/<[^>]+>/g, '')
      this.applyReason = reason
      this.setInformationDialogVisible = true
    }
  }
}
</script>

<style scoped>
.navigation {
  padding: 10px;
}

.notice {
  margin-bottom: 20px;
  border-radius: 15px;
  box-shadow: 15px 15px 10px -12px #4c61a0;
}

h4 {
  padding-bottom: 8px;
  margin-bottom: 20px;
  border-bottom: 2px solid #4c61a0;
}
</style>
